﻿using Architecture.Api.Application.CommandHandlers.CultureHandler;
using Architecture.Api.Application.Commands.CorporationCommand;
using Architecture.Api.Application.Commands.CultureCommand;
using Architecture.Api.Application.Commands.ImmuneInFormationCommand;
using Architecture.Domain.TraceabilityManage;
using Architecture.Domian.DTO;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Security.Claims;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;

namespace Architecture.Api.Controllers
{
    /// <summary>
    /// 养殖控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class CultureController : ControllerBase
    {
        private readonly IMediator _mediat;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediat"></param>
        public CultureController(IMediator mediat)
        {
            _mediat = mediat;
        }

        /// <summary>
        /// 添加养殖信息
        /// </summary>
        /// <param name="command">要添加的养殖实体</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> AddCultures(CultureCreateCommand command)
        {

            var data = HttpContext.User; //获取当前登录人所有Token 信息

            var id = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; //获取sub的值

            var role = HttpContext.User.FindFirst(ClaimTypes.Role)?.Value; //获取角色的值

            var userdata = HttpContext.User.FindFirst(ClaimTypes.UserData)?.Value; //用户自定义的值

            return await _mediat.Send(command);
        }

        /// <summary>
        /// 回显养殖信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        //[AllowAnonymous]
        public async Task<Culture> GetCultureInfo([FromQuery] CultureQueryInfoCommand command)
        {
            return await _mediat.Send(command);
        }

        /// <summary>
        /// 修改养殖信息
        /// </summary>
        /// <param name="command">要修改的养殖实体</param>
        /// <returns></returns>
        [HttpPut]
        public async Task<int> UpdateCultures(CultureUpdateCommand command)
        {
            return await _mediat.Send(command);
        }

        /// <summary>
        /// 批量操作公司照片
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> BatchCorporationPicList(CultrueBatchCorporationPicCommand command)
        {
            return await _mediat.Send(command);
        }

        /// <summary>
        /// 批量操作养殖动检证
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> BatchCulturePicList(CultrueBatchCulturePicCommand command)
        {
            return await _mediat.Send(command);
        }

        /// <summary>
        /// 获取公司照片
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<PictureDTO>> GetCorporationPicture([FromQuery] CultrueQueryCorporationPicListCommand command)
        {
            return await _mediat.Send(command);
        }

        /// <summary>
        /// 获取养殖动检证
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<PictureDTO>> GetCulturePicture([FromQuery] CultrueQueryCulturePicListCommand command)
        {
            return await _mediat.Send(command);
        }

        /// <summary>
        /// 添加养殖公司信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> AddCorporation(CorporationCreateCommand command)
        {
            return await _mediat.Send(command);
        }

        /// <summary>
        /// 回显养殖公司信息数据
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Corporation> GetCorporationInfo([FromQuery] CorporationQueryInfoCommand command)
        {
            return await _mediat.Send(command);
        }

        /// <summary>
        /// 修改养殖公司信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<int> UpdateCorporation(CorporationUpdateCommand command)
        {
            return await _mediat.Send(command);
        }

        /// <summary>
        /// 添加免疫信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> AddImmuneInFormation(ImmuneInFormationCreateCommand command)
        {
            return await _mediat.Send(command);
        }

        /// <summary>
        /// 修改免疫信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<int> UpdateImmuneInFormation(ImmuneInFormationUpdateCommand command)
        {
            return await _mediat.Send(command);
        }

        /// <summary>
        /// 回显免息信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ImmuneInFormation> GetImmuneInFormationInfo([FromQuery] ImmuneInFormationQueryInfoCommand command)
        {
            return await _mediat.Send(command);
        }

        /// <summary>
        /// 显示免疫信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<ImmuneInFormation>> GetImmuneInFormationList([FromQuery] ImmuneInFormationQueryCommand command)
        {
            return await _mediat.Send(command);
        }

        /// <summary>
        /// 删除免疫信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<int> DeleteImmuneInFormation([FromQuery] ImmuneInFormationInfoRemoveCommand command)
        {
            return await _mediat.Send(command);
        }
    }
}
